<?php
namespace app\admin\controller;

use app\common\controller\AdminBaseController;

use think\Db;
/**
 * 短信模板管理
 * Class SmsTemplate
 * @package app\admin\controller
 */
class SmsTemplate extends AdminBaseController {
	
	public function index(){
		$list = Db::table('sms_template')->order('update_time desc')->paginate(5);
        return $this->fetch('index', ['list' => $list]);
		
	}
	
	
	//添加短信模板
	
	
	public function add(){
		
		if(request()->isPost()){
			$data = input('post.');
			$data['update_time']=now_time();
			if (Db::table('sms_template')->insert($data)) {
                   return	toSuccess('添加成功');
                } else {
                   return toError(408,'添加失败');
                }
		}
		
	return $this->fetch();
	}
	
	
	
	public function update(){
		$id=input('id');
		if($_POST){
			$data['id']=$_POST['id'];
			$data['title']=$_POST['title'];
			$data['type']=$_POST['type'];
			$data['sign_name']=$_POST['sign_name'];
			$data['tid']=$_POST['tid'];
			$data['params']=$_POST['params'];
			$data['oem_id']=$_POST['oem_id'];
			$data['update_time']=now_time();
			if (Db::table('sms_template')->update($data)) {
               	return	toSuccess('更新成功');
            } else {
                return toError(408,'更新失败');
            }
		}
	$data=Db::table('sms_template')->where('id',$id)->find();
	return $this->fetch('update',['data'=>$data]);
	}
	
	
	    /**
     * [roleDel 删除]
     * @return [type] [description]
     */
    public function sms_del()
    {
        $id = input('id');
        if (Db::table('sms_template')->where('id',$id)->delete()) {
           return toSuccess('删除成功');
        } else {
           return toError(408,'删除失败，请重新删除');
        }
    }
	
	public function fas(){
		return $this ->get_code('15973240090',13);
	}
	
	
	
	public function smscode(){
		$list =Db::table('sms_code')->order('update_time desc')->paginate(10);
        return $this->fetch('smscode',['list' => $list]);
		
	}
	
	
	
	
	
}
